package com.wy.ifly;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Time:7/8/21
 * Author:ypf
 * Description:
 */
public class MyView extends View {

    private int[] ids = new int[]{R.mipmap.ten, R.mipmap.ten, R.mipmap.ten, R.mipmap.ten, R.mipmap.ten};
    private Bitmap[] imgs = new Bitmap[5];
    private Paint paint;

    public MyView(@NonNull Context context) {
        super(context);
        init();
    }

    public MyView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {

        for (int i = 0; i < ids.length; i++) {
            imgs[i] = BitmapFactory.decodeResource(getResources(), ids[i]);
        }

        paint = new Paint();
        paint.setAntiAlias(true);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        for (int i = 0; i < imgs.length; i++) {
            canvas.drawBitmap(imgs[i], i * 100, 0, paint);
        }

    }

}
